<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

Loader::loadThirdPart('Baidu', '', 'baidu');

class WgBaidu
{
    protected $_config = null;
    
    public function __construct() {
        $this->_config = Loader::loadConfig('baidu', 'member');
    }
    
    public function baidu_login() {
        $baidu = new Baidu($this->_config['app_key'], $this->_config['app_secret'], $this->_config['callback'], new BaiduCookieStore($clientId));
        $loginUrl = $baidu->getLoginUrl();
        header('Location:'.$loginUrl);
    }
    
    public function baidu_callback() {
        $baidu = new Baidu($this->_config['app_key'], $this->_config['app_secret'], $this->_config['callback'], new BaiduCookieStore($clientId));
        $user = $baidu->getLoggedInUser();
        if($user) {
            $_SESSION['baidu'] = $baidu->getAccessToken();
            $_SESSION['baiduid'] = $user['uid'];
            set_cookie('baidu', '1');
            return $user['uid'];
        }
        
        return false;
    }
}